#!/bin/bash
# 生成 FaceApi cpp client代码脚本
sh_folder=$(cd "$(dirname $0)"; pwd -P)
pushd "$sh_folder"
OUT_FOLDER=$sh_folder/src/faceapiclient/stub

# 指定thrift compiler位置
[ $(which thrift) >/dev/null ] && THRIFT_EXE=thrift
[ -z "$THRIFT_EXE" ] && THRIFT_EXE=$sh_folder/dependencies/dist/thrift-$(g++ -dumpmachine)/bin/thrift
$THRIFT_EXE --version || exit

if [ -e "$OUT_FOLDER" ] ;
then
	rm  "$OUT_FOLDER"/FaceApi*.c 1>/dev/null 2>/dev/null
	rm  "$OUT_FOLDER"/FaceApi*.h 1>/dev/null 2>/dev/null
	rm  "$OUT_FOLDER"/FeatureSe*.c 1>/dev/null 2>/dev/null
	rm  "$OUT_FOLDER"/FeatureSe*.h 1>/dev/null 2>/dev/null
else
echo $OUT_FOLDER
	mkdir -p "$OUT_FOLDER"
fi

$THRIFT_EXE --gen cpp:no_skeleton,moveable_types,templates \
	-out "$OUT_FOLDER" \
	"$sh_folder/../faceapi-service/FaceApi.thrift" || exit

$THRIFT_EXE --gen cpp:no_skeleton,moveable_types,templates \
	-out "$OUT_FOLDER" \
	"$sh_folder/../faceapi-service/FeatureSe.thrift" || exit

popd
